﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAL.Entities;

namespace DAL.EntitiesDAL
{
    public class thucdon_DAL:BaseDAL,UTL.IBaseDAL 
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT * FROM THUCDON";
            return ExecuteQuery(sql);
        }
        

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            string sql = @"DELETE FROM THUCDON WHERE MAMON = '{0}'";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (thucdon )obj;
            string sql = @"INSERT INTO THUCDON(MAMON, TENMON,MALOAI,DONGIA,DVT) VALUES('{0}',N'{1}', N'{2}', N'{3}', N'{4}') ";
            sql = string.Format(sql, o.MAMON, o.TENMON, o.MALOAI, o.DONGIA,o.DVT);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (thucdon )obj;
            string sql = @"SET dateformat dmy;UPDATE THUCDON SET TENMON=N'{1}',MALOAI=N'{2}',DONGIA=N'{3}',DVT=N'{4}' WHERE MAMON='{0}'";
            sql = string.Format(sql, o.MAMON, o.TENMON, o.MALOAI, o.DONGIA, o.DVT);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        public DataTable LOAIMON()
        {
            string sql = @" SELECT MALOAI AS id, TENLOAI AS ten FROM LOAIMON";
            return ExecuteQuery(sql);
        }

        public DataTable Select_max()
        {
            var sql = @"SELECT MAX(MAMON) as id FROM THUCDON";
            return ExecuteQuery(sql);
        }
         public string count_()
        {
            string sql = @"SELECT COUNT(MAMON) as id FROM THUCDON";
            var tb = ExecuteQuery(sql);
            return tb.Rows.Count > 0 ? tb.Rows[0]["id"] + "" : "0";
        }
    }
    }

